﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace DicomScu
{
    public class Logger
    {
        public static TextBox txtLog;

        public static void RegisterLog(TextBox txtTextBoxLog)
        {
            txtLog = txtTextBoxLog;
        }
        public delegate void DisplayLogEventHandler(string log);
        public static void WriteLog(string logText)
        {
            DisplayLogEventHandler d = new DisplayLogEventHandler(DisplayLog);
            Application.OpenForms[0].Invoke(d, new object[] { logText });
        }
        static void DisplayLog(string log)
        {
            if (txtLog == null)
                return;
            txtLog.Text += DateTime.Now.ToString("MM/dd/yyyy hh:mm") + " : " + log;
            txtLog.Text += "\r\n";
            txtLog.SelectionStart = txtLog.Text.Length;
            txtLog.ScrollToCaret();
            txtLog.Refresh();
            
        }
    }
}
